using System;
using System.Data;
using System.Collections;
using System.Text;

using EntLibEC.Cmn;
using System.Transactions;
using EntLibEC.Dac;

namespace EntLibEC.Biz.Basic
{
	/// <summary>
	/// Summary description for ZTestManager.
	/// </summary>
	public class ZTestManager
	{
		private ZTestManager()
		{
		}
		private static ZTestManager _instance;
		public static ZTestManager GetInstance()
		{
			if ( _instance == null )
			{
				_instance = new ZTestManager();
			}
			return _instance;
		}

		public DataSet GetColdDs(Hashtable paramHash)
		{
			string sql = @" select productid, productname, accountQty, username, intime, quantity, poid, currentprice, Ent_Product_Price.unitcost, accountqty*Ent_Product_Price.unitcost as totalCost
							from 
								Ent_Product, Ent_Inventory,Ent_PO_Master,Ent_PO_Item,Ent_Sys_User,Ent_Product_Price
							where
								Ent_Product.sysno = Ent_Inventory.productsysno
							and Ent_Product.sysno = Ent_PO_Item.productsysno
							and Ent_Product.sysno = Ent_Product_Price.productsysno
							and Ent_PO_Master.sysno = Ent_PO_Item.posysno
							and Ent_Product.pmusersysno = Ent_Sys_User.sysno
							and Ent_PO_Master.status = 4
							and accountqty<>0
							and Ent_PO_Master.intime<='2005-06-12'
and Ent_Product.sysno not in (select productsysno from Ent_PO_Master, Ent_PO_Item where Ent_PO_Master.sysno=Ent_PO_Item.posysno and Ent_PO_Master.status=4 and Ent_PO_Master.intime>='2005-06-12')
							order by productid, intime desc ";
			
			DataSet ds = SqlHelper.ExecuteDataSet(sql);
			DataSet ds2 = ds.Clone();
			string lastProductID="";
			foreach(DataRow dr in ds.Tables[0].Rows)
			{
				string currentProductID = Util.TrimNull(dr["productid"]);
				if ( currentProductID != lastProductID)
				{
					ds2.Tables[0].ImportRow(dr);
					lastProductID = currentProductID;
				}
			}

			return ds2;
			
		}
		
	}
}
